package com.comp6231.replica1.data;

import com.comp6231.replica1.exception.InvalidRecordStatusException;

/**
 * 
 * @author sknarula (narula.sk@gmail.com)
 * @since	September 2013
 * 
 * This is a class which extends class Record and contain additional 
 * criminal record related information
 *
 */
public class CriminalRecord extends Record {
	
	/**
	 * Attributes specific to Criminal Record
	 */
	public enum CriminalStatus {
	    CAPTURED, OTR 
	}
	private String crimeDescription;
	private CriminalStatus status;
	
	/**
	 * 
	 * @param fistName
	 * @param lastName
	 * @param crimeDescription
	 * @param criminalStatus
	 * 
	 * This is an constructor to create a criminal record
	 * @throws InvalidRecordStatusException 
	 */
	public CriminalRecord(String firstName, String lastName, String crimeDescription, String criminalStatus) 
			throws InvalidRecordStatusException {
		
		super(firstName, lastName, RecordType.CRIMINAL);
		this.recordId = "CR" + nextRecordId.getAndIncrement();
		this.crimeDescription = crimeDescription;
		this.setStatus(criminalStatus);
	}
	
	/**
	 * 
	 * @param recordId
	 * @param firstName
	 * @param lastName
	 * @param crimeDescription
	 * @param criminalStatus
	 * @throws InvalidRecordStatusException
	 * 
	 * Another constructor to create record by giving the record id as well
	 */
	public CriminalRecord(String recordId, String firstName, String lastName, String crimeDescription, String criminalStatus) 
			throws InvalidRecordStatusException {
		
		super(firstName, lastName, RecordType.CRIMINAL);
		this.recordId = recordId;
		this.crimeDescription = crimeDescription;
		this.setStatus(criminalStatus);
	}

	/**
	 * Getters and Setters
	 */
	
	public String getCrimeDescription() {
		return crimeDescription;
	}

	public void setCrimeDescription(String crimeDescription) {
		this.crimeDescription = crimeDescription;
	}

	public CriminalStatus getStatus() {
		return status;
	}

	public void setStatus(CriminalStatus status) {
		this.status = status;
	}

	public void setStatus(String newStatus) throws InvalidRecordStatusException {
		try {
			this.status = CriminalStatus.valueOf(newStatus);
		}
		catch (IllegalArgumentException e) {
			throw new InvalidRecordStatusException(newStatus + " is not a valid criminal status");
		}
		catch (NullPointerException e) {
			throw new InvalidRecordStatusException("Criminal status cannot be null");
		}
	}
	
	public String toString() {
		return "Criminal Record [" + this.getRecordId() + ", " + this.getFirstName() + ", " + this.getLastName() + ", " 
				+ this.getCrimeDescription() + ", " + this.getStatus() + "]";
	}
}
